package com.ldh.mod4j.businessdomain.generator.hibernate

import com.google.inject.Inject
import org.mod4j.dslcommon.generator.helpers.NameMapper
import org.mod4j.businessdomain.generator.helpers.BusinessClassHelpers
import org.mod4j.businessdomain.generator.helpers.BusinessDomainModelHelpers
import com.ldh.mod4j.businessdomain.businessDomainDsl.BusinessClass
import org.mod4j.dslcommon.xpand.java.JavaComments

class DaoInterfaceBase {
	@Inject extension JavaComments javaComments
	
	def daoInterfaceBase(BusinessClass clazz)'''
«javaComments.regenerationWarningHeader ("Mod4j BusinessDomainDsl generator: DaoInterfaceBase.xpt", clazz)»

package «NameMapper::getBusinessModelDataPackage(BusinessDomainModelHelpers::getModel(clazz).name)»;

import java.util.List;
import org.mod4j.runtime.queries.SearchParameters;

import «NameMapper::getFqnDomainClass(BusinessDomainModelHelpers::getModel(clazz).name, clazz.name)»;

/**
 * «NameMapper::javaDaoBaseInterface(clazz.name)»Data Access Object (DAO). Responsible for accessing database.
 * 
 * @author Mod4j generated
 * 
 */
public interface «NameMapper::javaDaoBaseInterface(clazz.name)» {

    /**
     * Retrieves a «NameMapper::javaDomainClass(clazz.name)» by its ID from the database.
     * 
     * @param id id of the «NameMapper::javaDomainClass(clazz.name)» to retrieve.
     * @return «NameMapper::javaDomainClass(clazz.name)» retrieved or null when no «NameMapper::javaDomainClass(clazz.name)» was found.
     */
    «NameMapper::javaDomainClass(clazz.name)» retrieve(Long id);

    /**
     * Adds a new «NameMapper::javaDomainClass(clazz.name)» to the database
     * 
     * @param object
     *                the «NameMapper::javaDomainClass(clazz.name)» to add to the database.
     * @return the stored «clazz.name».
     */
    Long add(«NameMapper::javaDomainClass(clazz.name)» object);

    /**
     * Deletes a «clazz.name» from the database.
     * 
     * @param object
     *                the «NameMapper::javaDomainClass(clazz.name)» to delete
     */
    void delete(«NameMapper::javaDomainClass(clazz.name)» object);

    /**
     * Selects all «NameMapper::javaDomainClass(clazz.name)»s from the database.
     * 
     * @return a List of all «NameMapper::javaDomainClass(clazz.name)» objects.
     */
    List<«NameMapper::javaDomainClass(clazz.name)»> listAll();

    /**
     * Selects a range (page) of «NameMapper::javaDomainClass(clazz.name)»s from the database.
     * 
     * @param firstResult the index of the first result object to be retrieved (numbered from 0)
     * @param maxResults  the maximum number of result objects to retrieve (or <=0 for no limit) 
     * 
     * @return a List containing 0 or more «NameMapper::javaDomainClass(clazz.name)» objects.
     *
     * @see #listPage(int, int)
     */
    List<«NameMapper::javaDomainClass(clazz.name)»> listPage(final int firstResult, final int maxResults);

    /**
     * Selects a sorted range (page) of «NameMapper::javaDomainClass(clazz.name)»s from the database.
     * 
     * @param firstResult the index of the first result object to be retrieved (numbered from 0)
     * @param maxResults the maximum number of result objects to retrieve (or <=0 for no limit)
     * @param sortProperty the property of the object to sort on
     * @param isAscending should the retruned list be sorted ascending? 
     * 
     * @return a sorted List containing 0 or more «NameMapper::javaDomainClass(clazz.name)» objects.
     *
     * @see #listPage(int, int, String, boolean)
     */
    List<«NameMapper::javaDomainClass(clazz.name)»> listPage(final int firstResult, final int maxResults,
        final String sortProperty, final boolean isAscending);
        
    /**
     * @deprecated Instead use {@link #findByExample(«NameMapper::javaDomainClass(clazz.name)», SearchParameters)}.
     *
     * Selects a sorted range (page) of «NameMapper::javaDomainClass(clazz.name)»s from the database.
     * 
     * @param example the example object to which the result objects need to conform
     * @param firstResult the index of the first result object to be retrieved (numbered from 0)
     * @param maxResults the maximum number of result objects to retrieve (or <=0 for no limit)
     * @param sortProperty the property of the object to sort on
     * @param isAscending should the retruned list be sorted ascending? 
     * 
     * @return a sorted List containing 0 or more «NameMapper::javaDomainClass(clazz.name)» objects.
     *
     * @see #listPage(int, int, String, boolean)
     */
    List<«NameMapper::javaDomainClass(clazz.name)»> listPageByExample(final «NameMapper::javaDomainClass(clazz.name)» example, final int firstResult, final int maxResults,
            final String sortProperty, final boolean isAscending);

    /**
     * Counts the number of persisted «NameMapper::javaDomainClass(clazz.name)» objects in the database.
     * 
     * @return the number of persisted objects in the database.
     */
    long count();
    
    /**
     * @deprecated Instead use {@link countByExample(«NameMapper::javaDomainClass(clazz.name)»)} or 
     *     {@link countByExample(«NameMapper::javaDomainClass(clazz.name)» example, SearchParameters parameters)}.
     *
     * Counts the number of persisted «NameMapper::javaDomainClass(clazz.name)» objects in the database that
     * matches the given example object.
     *
     * @param example
     *                the example object to be counted
     * 
     * @return the number of persisted objects in the database.
     */
    long count(final «NameMapper::javaDomainClass(clazz.name)» example);

    /**
     * Counts the number of persisted «NameMapper::javaDomainClass(clazz.name)» objects in the database that
     * matches the given <code>example</code> object. By default the match mode will be set to 'anywhere',
     * and the case of string-valued properties will be ignored.
     *
     * @param example
     *                the example object to be counted
     * 
     * @return the number of persisted objects in the database.
     * @since 1.4
     */
    long countByExample(«NameMapper::javaDomainClass(clazz.name)» example);

    /**
     * Counts the number of persisted «NameMapper::javaDomainClass(clazz.name)» objects in the database that
     * matches the given <code>example</code> object and is constrained by the given search <code>parameters</code>.
     *
     * @param example
     *                the example object to be counted
     * @param parameters
     *                the set of search parameters that specifies the search criteria.
     * 
     * @return the number of persisted objects in the database.
     * @since 1.4
     */
    long countByExample(«NameMapper::javaDomainClass(clazz.name)» example, SearchParameters parameters);

    /**
     * Selects «NameMapper::javaDomainClass(clazz.name)»s from the database that matches the
     * given <code>example</code> object. By default the match mode will be set to 'anywhere',
     * and the case of string-valued properties will be ignored.
     * 
     * @param example
     *                the example object to which the result objects need to conform
     * @return a List of «NameMapper::javaDomainClass(clazz.name)» objects.
     */
    List<«NameMapper::javaDomainClass(clazz.name)»> findByExample(«NameMapper::javaDomainClass(clazz.name)» example);
    
    /**
     * Selects «NameMapper::javaDomainClass(clazz.name)»s from the database that matches the given
     * <code>example</code> object, and is constrained by the given search <code>parameters</code>.
     * 
     * @param example
     *                the example object to which the result objects need to conform
     * @param parameters
     *                the set of search parameters that specifies the search criteria.
     * @return a List of «NameMapper::javaDomainClass(clazz.name)» objects.
     * @since 1.4
     */
    List<«NameMapper::javaDomainClass(clazz.name)»> findByExample(«NameMapper::javaDomainClass(clazz.name)» example, SearchParameters parameters);
}
'''
}